<?php
/**
 * Created by PhpStorm.
 * User: s.utkin
 * Date: 17.12.2014
 * Time: 14:55
 */

namespace Jobs\FlashMessages;


use FlashMessages\FlashMessage;

class RemoveProcessedAction extends \Action {

	/**
	 * Диспетчер очереди уведомлений
	 */
	protected function run()
	{
		$this->response->noRender(true);
		$startTime = time();



		while (true) {
			$deleteUpdater = FlashMessage::delete();
			$deleteUpdater->where('isProcessed', true);
			$deleteUpdater->limit(1000);
			$deleteUpdater->delete()
				->execute();

			usleep(100000);
			$currentTime = time();

			if (($currentTime - $startTime) > 60) {
				break;
			}
		}
	}
}